package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.ProductBean;
import com.project.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("product")
public class ProductController {
    @Autowired
    private IProductService productService;

    @RequestMapping("findByItem")
    public String findByItem(HttpServletRequest req, String name,
                             @RequestParam(value = "pageNO",
                                     defaultValue = "1") Integer pageNO){
        IPage<ProductBean> ip = productService.findByItem(pageNO,name);
        req.setAttribute("pg",ip);
        req.setAttribute("name",name);
        return "/index.html";
    }

    @RequestMapping("findById")
    public String findById(Integer id,HttpServletRequest req){
        ProductBean product = productService.findById(id);
        req.setAttribute("product",product);
        return "/findById.html";
    }
}
